#include "headers/common.h"
#include "../api/headers/io.h"
#include "../api/headers/errors.h"
#include "../multitasking/headers/task.h"
extern u32int globalInt;
extern task_t* focused_task;
extern task_t* current_task;

extern void panic(const char *message, const char *file, u32int line)
{
    //We encountered a massive problem and have to stop.
	//asm volatile("cli"); // Disable interrupts.
	
	printf("PANIC(%s) at %s: %d\n", message, file, line);
	printf("Last error: %d - %s\n", getLastError(), getLastErrorMessage());
	if(getpid() != 1) //If not kernel
		asm volatile ("sti");
	//asm volatile("hlt");
	for(;;);
}

extern void kernel_panic(const char* message, const char* file, u32int line)
{
	//Kill all processes
	asm volatile ("cli");
	setCurrentVirtualConsole(focused_task->console);
	printf("Irrecoverable kernel error at process %d has occured:\n\"%s\" at %s : %d\n", current_task->id, message, file, line);
	printf("Last error: %d - %s\n", getLastError(), getLastErrorMessage());
	asm volatile ("hlt");
	for(;;);
}

extern void panic_assert(const char *file, u32int line, const char *desc)
{
    // An assertion failed, and we have to panic.
	//asm volatile("cli"); // Disable interrupts.
	printf("ASSERTION-FAILED(%s) at %s: %d\n", desc, file, line);
	printf("Last error: %d - %s\n", getLastError(), getLastErrorMessage());
	for(;;);
    // Halt by going into an infinite loop.
	//asm volatile("hlt");
}
